﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using YJKInspectModelFunc.ModelLayer;

namespace YJKSparseDistance.ModelLayer
{
	public class RoomCurveBean : BaseCurveBean
	{
		public BaseRoomPacker ThisPacker
		{
			get
			{
				return this.m_thisPacker;
			}
		}

		public Room ThisRoom
		{
			get
			{
				return this.m_thisRoom;
			}
		}

		public int thisPackerId
		{
			get
			{
				return this.m_nthisPackerId;
			}
		}

		public int thisRoomId
		{
			get
			{
				return this.m_nthisRoomId;
			}
		}

		internal List<BoundaryCurveArrayBean> LstBoundaryCurveArrayBeans
		{
			get
			{
				return this.m_lstBoundaryCurveArrayBeans;
			}
		}

		internal List<DoorCurveBean> LstDoorCurveBean
		{
			get
			{
				return this.m_lstDoorCurveBean;
			}
		}

		public List<RoomCurveBean> LstLinkRoomCurveBean
		{
			get
			{
				return this.m_lstLinkRoomCurveBean;
			}
		}

		internal List<ObstructureCurveBean> LstObstructureCurveBean
		{
			get
			{
				return this.m_lstObstructureCurveBean;
			}
		}

		public override List<BulidingCurvePakcer> LstCurvePacker
		{
			get
			{
				List<BulidingCurvePakcer> list = new List<BulidingCurvePakcer>();
				list.AddRange(this.m_lstCurvePacker);
				foreach (DoorCurveBean doorCurveBean in this.LstDoorCurveBean)
				{
					list.AddRange(doorCurveBean.LstCurvePacker);
				}
				return list;
			}
		}

		public override List<XYZ> LstAllFreeEnd
		{
			get
			{
				List<XYZ> list = new List<XYZ>();
				foreach (BoundaryCurveArrayBean boundaryCurveArrayBean in this.m_lstBoundaryCurveArrayBeans)
				{
					list.AddRange(boundaryCurveArrayBean.LstAllFreeEnd);
				}
				foreach (DoorCurveBean doorCurveBean in this.m_lstDoorCurveBean)
				{
					list.AddRange(doorCurveBean.LstAllFreeEnd);
				}
				foreach (ObstructureCurveBean obstructureCurveBean in this.m_lstObstructureCurveBean)
				{
					list.AddRange(obstructureCurveBean.LstAllFreeEnd);
				}
				return list;
			}
		}

		public List<BulidingCurvePakcer> LstObstructureCurvePacker
		{
			get
			{
				List<BulidingCurvePakcer> list = new List<BulidingCurvePakcer>();
				foreach (ObstructureCurveBean obstructureCurveBean in this.LstObstructureCurveBean)
				{
					list.AddRange(obstructureCurveBean.LstCurvePacker);
				}
				return list;
			}
		}

		public List<WallLocationCurveBean> LstWallLocationCurveBean
		{
			get
			{
				return this.m_lstWallLocationCurveBean;
			}
			private set
			{
				this.m_lstWallLocationCurveBean = value;
			}
		}

		public RoomCurveBean(BaseRoomPacker inputValue)
		{
			this.m_thisPacker = inputValue;
			this.m_thisRoom = this.ThisPacker.ThisRoom;
			this.m_nthisPackerId = this.ThisPacker.ThisElementPackerId;
			this.m_nthisRoomId = this.ThisRoom.Id.IntegerValue;
			foreach (List<BaseBoundarySegmentPacker> inputValue2 in inputValue.LstLstBoundarySegmentPacker)
			{
				this.LstBoundaryCurveArrayBeans.Add(new BoundaryCurveArrayBean(inputValue2));
			}
			foreach (BoundaryCurveArrayBean boundaryCurveArrayBean in this.LstBoundaryCurveArrayBeans)
			{
				this.LstWallLocationCurveBean.AddRange(boundaryCurveArrayBean.LstAllWallLocationCurves);
				this.m_lstCurvePacker.AddRange(boundaryCurveArrayBean.LstCurvePacker);
			}
			this.LstWallLocationCurveBean = this.LstWallLocationCurveBean.Distinct<WallLocationCurveBean>().ToList<WallLocationCurveBean>();
			foreach (BoundaryCurveArrayBean boundaryCurveArrayBean2 in this.LstBoundaryCurveArrayBeans)
			{
				this.LstDoorCurveBean.AddRange(boundaryCurveArrayBean2.LstDoorCurveBean);
			}
			double elevation = this.m_thisRoom.Level.Elevation;
			foreach (KeyValuePair<BaseHostInRoomPacker, XYZ> keyValuePair in inputValue.LstHostElementPacker)
			{
				if (keyValuePair.Key is ObstructurePacker_EvacuationDistance && keyValuePair.Key is ObstructurePacker_EvacuationDistance)
				{
					this.m_lstObstructureCurveBean.Add(new ObstructureCurveBean(keyValuePair.Key as ObstructurePacker_EvacuationDistance, elevation));
				}
			}
		}

		public bool SetLinkedRoom(RoomCurveBean inputValue)
		{
			if (this == inputValue || this.thisRoomId == inputValue.thisRoomId)
			{
				return false;
			}
			bool flag = false;
			for (int i = 0; i < this.LstDoorCurveBean.Count; i++)
			{
				for (int j = 0; j < inputValue.LstDoorCurveBean.Count; j++)
				{
					bool flag2 = this.LstDoorCurveBean[i].CutThisDoor(inputValue.LstDoorCurveBean[j]);
					flag = (flag || flag2);
				}
			}
			if (flag)
			{
				this.LstLinkRoomCurveBean.Add(inputValue);
				inputValue.LstLinkRoomCurveBean.Add(this);
			}
			return flag;
		}

		private BaseRoomPacker m_thisPacker;

		private Room m_thisRoom;

		private int m_nthisPackerId;

		private int m_nthisRoomId;

		private List<BoundaryCurveArrayBean> m_lstBoundaryCurveArrayBeans = new List<BoundaryCurveArrayBean>();

		private List<DoorCurveBean> m_lstDoorCurveBean = new List<DoorCurveBean>();

		private List<RoomCurveBean> m_lstLinkRoomCurveBean = new List<RoomCurveBean>();

		private List<ObstructureCurveBean> m_lstObstructureCurveBean = new List<ObstructureCurveBean>();

		private List<WallLocationCurveBean> m_lstWallLocationCurveBean = new List<WallLocationCurveBean>();
	}
}
